package fr.ups.jim.isi.tp7 ;

import java.awt.Color;
import javax.swing.JFrame;
import java.awt.Font;
import fr.lri.swingstates.canvas.CPolyLine;
import fr.lri.swingstates.canvas.CRectangle;
import fr.lri.swingstates.canvas.Canvas;
import fr.lri.swingstates.gestures.AbstractClassifier;
import fr.lri.swingstates.gestures.rubine.RubineClassifier;
import fr.lri.swingstates.sm.StateMachineListener;
import fr.lri.swingstates.canvas.CExtensionalTag;
import fr.lri.swingstates.canvas.CHierarchyTag;
import fr.lri.swingstates.canvas.CStateMachine;
import fr.lri.swingstates.canvas.CShape;

public class GestureRecognition extends JFrame{

    Canvas canvas;

    public GestureRecognition() {
	   setSize(600, 600);
	   canvas = new Canvas(600, 600);
	   RubineClassifier classifier = null;
	   classifier = RubineClassifier.newClassifier("images/vocabulary.cl");
	   recognizedGestures(classifier);
	   InkMachine sm = new InkMachine(classifier, canvas);
	   sm.attachTo(canvas);
	   add(canvas);
	   setVisible(true) ;
    }
	
    void recognizedGestures(AbstractClassifier classifier) {
	   CRectangle bar = new CRectangle(10.0,25.0,150,60);
	   CRectangle bar2 = new CRectangle(150.0,25.0,150,60);
		
	   bar.setFillPaint(Color.lightGray);
	   canvas.addShape(bar);
	   canvas.addShape(bar2);
	   canvas.newText(320, 45, " Geste reconnu : ", new Font("Verdana", Font.PLAIN, 14));
		
	   canvas.newText(10, 10, "Gestes possibles : ");
	   for(int i = 0; i < classifier.getClassesNames().size(); i++) {
		  CPolyLine gest = classifier.getRepresentative(classifier.getClassesNames().get(i));
		  gest.addTo(canvas).scaleBy(25 / gest.getHeight(), 25 / gest.getWidth()).translateTo(50 + 70*i, 50);
		  canvas.newText(0, 0, classifier.getClassesNames().get(i)).translateTo(gest.getCenterX(), bar.getMaxY() - 10);			
	   }
    }
	
    public static void main(String[] args) {
	   GestureRecognition gr = new GestureRecognition() ;
	   gr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
    }

}


